<template>
    <!-- 
    <b-modal ref="my-modal" hide-footer title="Using Component Methods">
     <div class="d-block text-center">
       <h3>Hello From My Modal!</h3>
     </div>
     <b-button class="mt-3" variant="outline-danger" block @click="hideModal">Close Me</b-button>
     <b-button class="mt-2" variant="outline-warning" block @click="toggleModal">Toggle Me</b-button>
   </b-modal> 
    -->
    <!--
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
    -->
    <b-modal ref="my-modal" :title="title" scrollable no-close-on-backdrop>
        <div class="d-block text-center">
            <!--begin::div-->
            <div class="m-form m-form--fit m-form--label-align-left m-form--group-seperator-dashed">
                <div class="m-portlet__body">
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">字典名称</label>
                        <div class="col-lg-4">
                            <input class="form-control placeholder-no-fix" type="text" placeholder="请输入" v-model="dataDictionaryForm.xt_data_dictionary_name"/> 
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">键&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;值</label>
                        <div class="col-lg-4">
                            <input class="form-control placeholder-no-fix" type="hidden" placeholder="请输入" v-model="dataDictionaryForm.xt_data_dictionary_pid"/> 
                            <input class="form-control placeholder-no-fix" type="text" placeholder="请输入" v-model="dataDictionaryForm.xt_data_dictionary_value"/> 
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态</label>
                        <div class="col-lg-4">
                            <select class="form-control" v-model="dataDictionaryForm.xt_data_dictionary_state">
                                <option value="0">启用</option>
                                <option value="1">禁用</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">排&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;序</label>
                        <div class="col-lg-2">
                            <el-input-number 
                            v-model="dataDictionaryForm.xt_data_dictionary_soft" 
                            maxlength="10" 
                            style="width:100px;" 
                            controls-position="right"
                             :min="0" 
                             :max="10">
                            </el-input-number>
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注</label>
                        <div class="col-lg-8">
                            <textarea class="form-control" cols="100" maxlength="200"  v-model="dataDictionaryForm.xt_data_dictionary_remark" placeholder="请输入"></textarea>		                    
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <template slot="modal-footer">
            <!--自定义按钮-->
            <button type="button" class="btn btn-light-danger font-weight-bold mr-2" block @click="hideModal">
                <i class="icon-xl fa fa-times"></i>取消
            </button> 
            <button type="button" class="btn btn-light-success font-weight-bold mr-2" @click="addXtDataDictionary">
                <i class="icon-xl fas fa-save"></i> 保存
            </button>
        </template>
    </b-modal>        
</template>
<script>
import apiUtil from "@/core/util/apiUtil.js"; 
import { handleNotify,handleAlert,handleConfirm,showWating,closeWating} from "@/core/util/jehcUtil.js";
export default {
    data(){
        return {   
            title:"新建数据字典", 
            dataDictionaryForm:{
                xt_data_dictionary_name: "",
                xt_data_dictionary_value:"",
                xt_data_dictionary_state:"0",
                xt_data_dictionary_soft:"",
                xt_data_dictionary_pid:"0",
            }
        }
    },
    components: {
        
    },
    watch: {
    },
    mounted() {
        
    },
    methods: {
        addXtDataDictionary(){
            if(this.dataDictionaryForm.xt_data_dictionary_name === ""){
                handleAlert("请输入名称", "warning", 3)
                return;
            }
            if(this.dataDictionaryForm.xt_data_dictionary_value === ""){
                handleAlert("请输入键值", "warning", 3)
                return;
            }
            if(this.dataDictionaryForm.xt_data_dictionary_state === ""){
                handleAlert("请选择状态", "warning", 3)
                return;
            }
            if(this.dataDictionaryForm.xt_data_dictionary_soft === ""){
                handleAlert("请输入排序号", "warning", 3)
                return;
            }
            // 保存前提示
            this.$confirm("确定保存?", "提示", {type: "warning",}).then(() => {
                apiUtil.post(process.env.VUE_APP_SYS_API+"/xtDataDictionary/add", this.dataDictionaryForm).then(({ data }) => {
                    if(data.success){
                        handleAlert("创建成功", "success", 3);
                        this.hideModal();//关闭窗体
                        this.$emit("change",data);//组件传值，即向父级模态框中传递值，采用change方式，目标刷新主列表使用
                    }else {
                        handleAlert("创建失败", "error", 3);
                    }            
                });
            }).catch(()=>{});//注意这里，这里是重点！！！;   
        },
        showModal(pid,type,name) {
            this.restForm();
            // if(type == "0"){
            //     this.title="新建数据字典->"+name
            // }
            // if(type == "1"){
            //     this.title="新建数据字典"+name
            // }
            this.title="新建数据字典->"+name
            this.dataDictionaryForm.xt_data_dictionary_pid = pid;
            this.$refs['my-modal'].show();
        },
        hideModal() {
            this.$refs['my-modal'].hide()
        },
        toggleModal() {
            // 当模态已隐藏时，我们传递要返回焦点的按钮的ID
            this.$refs['my-modal'].toggle('#toggle-btn')
        },
        restForm(){
            //重置
            Object.assign(this.$data.dataDictionaryForm, this.$options.data().dataDictionaryForm);
        },
   }
}
</script>